# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _

class hr_employee(osv.osv):
    _inherit = "hr.employee"

    _columns = {
        'mdb_user_id': fields.integer('User Id at MDB Files'),
    }

    def create(self, cr, uid, data, context=None):
        if 'mdb_user_id' in data:
            if data['mdb_user_id'] > 0:
#                 if self.search(cursor, user, [('name', '=', part.name),('id', '!=', part.id)]):
                if self.search(cursor, user, [('mdb_user_id', '=', data['mdb_user_id'])]):
                    raise osv.except_osv(_('User Id has been used at other employees'), _("User Id %s has been used by other employees"%data['mdb_user_id']))
        return super(hr_employee, self).create(cr, uid, data, context)

    def write(self, cr, uid, ids, vals, context=None):
        if 'mdb_user_id' in vals:
            if vals['mdb_user_id'] > 0:
                 if self.search(cr, uid, [('mdb_user_id', '=', vals['mdb_user_id']),('id', '!=', ids[0])]):
                    raise osv.except_osv(_('User Id has been used at other employees'), _("User Id %s has been used by other employees"%vals['mdb_user_id']))
        return super(hr_employee, self).write(cr, uid, ids, vals, context=context)
hr_employee()


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
